import http from '@/utils/request.ts'
import type { NameSpace, CreateNameSpaceRequest } from '@/modules/doc/types/namespace.ts'

export const namespaceApi = {
  // 获取所有命名空间
  getAll: async (): Promise<NameSpace[]> => {
    const response = await http.get<NameSpace[]>('/namespace/list')
    return response.data || []
  },

  // 创建命名空间
  create: async (request: CreateNameSpaceRequest): Promise<NameSpace> => {
    const response = await http.post<NameSpace>('/namespace', request)
    return response.data
  },

  // 更新命名空间
  update: async (id: string, request: CreateNameSpaceRequest): Promise<NameSpace> => {
    const response = await http.put<NameSpace>(`/namespace/${id}`, request)
    return response.data
  },

  // 删除命名空间
  delete: async (id: string): Promise<void> => {
    await http.delete(`/namespace/${id}`)
  }
}